<template>
  <div class="aside-container">
    <div class="aside_head">
      <div class="left">
        <Title :title_text="title_text" class="aside_title"></Title>
      </div>
      <div class="right">
        <Button
          v-if="btn_text"
          icon_end="icon-arrow-right"
          :btn_text="btn_text"
        ></Button>
      </div>
    </div>
    <div class="aside_body">
      <ul class="rank_list">
        <li class="rank_item" v-for="item in rankList" :key="item.id">
          <div class="item_wrapper">
            <span
              :class="{
                rank_num: true,
                rank_first: item.order === 1,
                rank_second: item.order === 2,
                rank_third: item.order === 3
              }"
              >{{ item.order }}</span
            >
            <a :href="item.link" :title="item.title" target="_blank">
              <div class="img_box" v-if="item.order === 1">
                <img :src="item.imgLink" alt="" />
              </div>
              <div class="info_box">
                <h3 class="rank_content">{{ item.title }}</h3>
              </div>
            </a>
          </div>
          <div :class="{ pop: true, first_pop: item.order === 1 }">
            <div class="pop_left">
              <img :src="item.imgLink" />
            </div>
            <div class="pop_right">{{ item.title }}</div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import Title from '@/components/Title';
import Button from '@/components/Button';
export default {
  name: 'Aside',
  components: {
    Title,
    Button
  },
  props: {
    title_text: {
      default: '标题',
      type: String
    },
    // 右上角按钮文字，如果没有则不显示按钮
    btn_text: {
      default: '更多',
      type: String
    },
    rankList: {
      default: [],
      type: Array
      // required: true
    }
  }
};
</script>

<style lang="less" scoped>
.aside-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  .aside_head {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    .left {
      display: flex;
      align-items: center;
      .aside_title {
        margin-left: 14px;
        margin-right: 10px;
      }
    }
  }
  .aside_body {
    flex: 1;
    .rank_list {
      border-radius: 6px;
      border: 1px solid #f1f2f3;
      background-color: #f6f7f8;
      height: 100%;
      box-sizing: border-box;
      display: grid;
      .rank_item {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        padding: 0 8px;
        min-width: 0;
        position: relative;
        cursor: pointer;
        &:nth-child(odd) {
          background-color: #fff;
        }
        &:hover {
          .pop {
            opacity: 1;
            transform: scale3d(1, 1, 1);
          }
        }
        .pop {
          position: absolute;
          top: -80px;
          left: -23px;
          width: 316px;
          height: 80px;
          background-color: #fff;
          z-index: 3;
          border-radius: 10px;
          border: 1px solid #ccc;
          box-shadow: 5px 5px 15px 0px #acacac;
          display: flex;
          align-items: center;
          justify-content: flex-start;
          opacity: 0;
          transform: scale3d(0, 0, 0);
          transform-origin: center;
          transition: all 0.3s linear;
          &:hover {
            opacity: 0;
            transform: scale3d(0, 0, 0);
          }
          &.first_pop {
            top: -84px;
          }
          .pop_left {
            width: 90px;
            height: 56px;
            margin: 10px;
            img {
              width: 100%;
              height: 100%;
              object-fit: cover;
              border-radius: 8px;
            }
          }
          .pop_right {
            flex: 1;
            font-size: 1.4rem;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            padding-right: 10px;
          }
        }
        .item_wrapper {
          display: flex;
          align-items: center;
          justify-content: flex-start;
          width: 100%;
          height: 100%;
          .rank_num {
            margin-right: 6px;
            width: 20px;
            font-style: italic;
            font-weight: bold;
            font-size: 1.4rem;
            text-align: center;
            line-height: 20px;
            color: #c9ccd0;
            &.rank_first {
              color: #ff473d;
            }
            &.rank_second {
              color: #ff6a29;
            }
            &.rank_third {
              color: #ff9214;
            }
          }
          a {
            display: flex;
            justify-content: flex-start;
            align-items: stretch;
            flex: 1;
            width: 100%;
            color: #18191c;
            min-width: 0;
            .img_box {
              margin-right: 6px;
              width: 90px;
              height: 56px;
              img {
                width: 100%;
                height: 100%;
                object-fit: cover;
                border-radius: 4px;
              }
            }
            .info_box {
              font-size: 1.4rem;
              display: flex;
              align-items: flex-start;
              justify-content: space-between;
              flex-direction: column;
              min-width: 0;
              flex: 1;
              .rank_content {
                white-space: nowrap;
                text-overflow: ellipsis;
                overflow: hidden;
                width: 100%;
                transition: color 0.3s linear;
                &:hover {
                  color: #00aeec;
                }
              }
            }
          }
        }
      }
    }
  }
}
</style>
